package com.gitee.xmhzzz.component.common.context;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.gitee.xmhzzz.component.common.dto.BaseInfo;

/**
 * @ClassName UserInfoContext
 * @Description
 * @Author wzq
 * @Date 2023/8/14 18:59
 * @Version 1.0
 */
public class UserContext {

    static TransmittableThreadLocal<String> USER_ID = new TransmittableThreadLocal<String>();

    static TransmittableThreadLocal<BaseInfo> BASE_INFO = new TransmittableThreadLocal<BaseInfo>();


    public static BaseInfo getBaseInfo()
    {
        return BASE_INFO.get();
    }

    public static void setBaseInfo(BaseInfo baseInfo)
    {
        BASE_INFO.set(baseInfo);
    }

    public static String getUserId()
    {
        return USER_ID.get();
    }

    public static void setUserId(String userId)
    {
        USER_ID.set(userId);
    }

    public static void clear()
    {
        if(USER_ID != null)
        {
            USER_ID.remove();
        }

        if(BASE_INFO != null)
        {
            BASE_INFO.remove();
        }
    }
}
